package io.kiki.stack.http.feign.SpringMvcContract.loadbalancer;

import io.kiki.stack.http.feign.Request;
import org.springframework.cloud.client.ServiceInstance;
import org.springframework.core.annotation.Order;

/**
 * Allows applications to transform the load-balanced {@link Request} given the chosen
 * {@link org.springframework.cloud.client.ServiceInstance}.
 */
@Order(LoadBalancerFeignRequestTransformer.DEFAULT_ORDER)
public interface LoadBalancerFeignRequestTransformer {

    /**
     * Order for the {@link LoadBalancerFeignRequestTransformer}.
     */
    int DEFAULT_ORDER = 0;

    /**
     * Allows transforming load-balanced requests based on the provided
     * {@link ServiceInstance}.
     *
     * @param request  Original request.
     * @param instance ServiceInstance returned from LoadBalancer.
     * @return New request or original request
     */
    Request transformRequest(Request request, ServiceInstance instance);

}
